package com.warren.auth.handler;


import com.warren.auth.utils.JSONAuthentication;
import com.warren.response.Result;
import com.warren.response.ResultCode;

import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;

import java.io.IOException;

/**
 * @author warren
 * @date 2021/3/31 0031 14:02
 * @Description 被挤下线
 **/
@Component
public class MyInvalidSessionStrategy extends JSONAuthentication implements SessionInformationExpiredStrategy {



    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent sessionInformationExpiredEvent) throws IOException, ServletException {
        Result result = Result.error(ResultCode.USER_SESSION_INVALID);

        this.WriteJSON(sessionInformationExpiredEvent.getRequest(),
                sessionInformationExpiredEvent.getResponse(),result);
    }
}
